package com.session03;

public class Student {
    private String name;
    private int age;

    public Student() {

    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof Student) {
            Student stu = (Student) o;
            if (stu.getName().equals(this.name) &&
                    stu.getAge() == this.age) {
                return true;
            }

        }
        return false;
    }


    @Override
    public int hashCode() {
        int result = 0;
        char[] charArray = this.name.toCharArray();
        for (char c : charArray) {
            result += c;
        }
        result += this.age;
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
